package com.qzsoft.zhjd.cement.modules.cementoutputsummary.service.impl;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.ConvertDictUtils;
import com.qzsoft.zhjd.cement.modules.cementoutputsummary.dto.CementOutputSummaryDto;
import com.qzsoft.zhjd.cement.modules.cementoutputsummary.mapper.CementOutputSummaryMapper;
import com.qzsoft.zhjd.cement.modules.cementoutputsummary.service.CementOutputSummaryService;
import com.qzsoft.zhjd.common.annotation.ZhjdDataFilter;
import com.qzsoft.zhjd.common.components.BaseServiceComponent;
import com.qzsoft.zhjd.common.excel.ZhjdExcelExportUtils;
import com.qzsoft.zhjd.common.excel.style.ZhjdExcelExportStyler;
import com.qzsoft.zhjd.common.utils.RenExceptionUtils;

import cn.afterturn.easypoi.excel.entity.ExportParams;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName CementOutputSummaryServiceImpl
 * @Description 水稳产量统计汇总业务接口实现
 * @author linhuawei
 * @since 2022-04-24
 */
@Slf4j
@Service
public class CementOutputSummaryServiceImpl implements CementOutputSummaryService {
    
    @Autowired
    private CementOutputSummaryMapper cementOutputSummaryMapper;

    @Autowired
    private BaseServiceComponent baseServiceComponent;

    @Override
    @ZhjdDataFilter(tableAlias = "t1")
    public IPage<CementOutputSummaryDto> page(Map<String, Object> params) {
        IPage<CementOutputSummaryDto> page = baseServiceComponent.getPage(params, CementOutputSummaryDto.class);
        IPage<CementOutputSummaryDto> dataPage = cementOutputSummaryMapper.queryDto(page, params);
        return ConvertDictUtils.formatDicDataPage(dataPage);
    }

    @Override
    @ZhjdDataFilter(tableAlias = "t1")
    public void export(Map<String, Object> params, HttpServletResponse response) {
        List<CementOutputSummaryDto> dataList = cementOutputSummaryMapper.queryDto(params);
        List<CementOutputSummaryDto> list = ConvertDictUtils.formatDicDataList(dataList);
        String fileName = "水稳产量统计汇总";
        ExportParams exportParams = new ExportParams(null, fileName);
        exportParams.setFixedTitle(false);
        exportParams.setStyle(ZhjdExcelExportStyler.class);
        try {
            ZhjdExcelExportUtils.exportExcel(response, fileName, exportParams, CementOutputSummaryDto.class, list);
        } catch (IOException e) {
            log.error("水稳产量统计汇总导出失败：{}", e);
            RenExceptionUtils.throwEx("数据导出失败");
        }

    }

}
